
import { Route, Redirect } from 'react-router-dom';
import { getToken } from 'utils/Token';

export default function authRoute({ component: Com, ...rest }) {
    return (
        <Route
            // path={path}
            {...rest}
            render={(props) => {
                const token = getToken()
                if (token) {
                    return <Com {...props} />
                } else {
                    return <Redirect to={
                        {
                            pathname: '/login',
                            state: {
                                from: props.location
                            }
                        }
                    } />
                }

            }}
        />
    )
}
